import time
import pytest
from playwright.sync_api import sync_playwright
@pytest.fixture
def page():
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False)
        page = browser.new_page()

        page.goto('https://www.jiuxian.com/')
        yield page
        page.close()
def test_jiouxian_01(page):
    page.click('a[class="headerLogin"]')
    dy1 = page.locator('a[class="userLogin on"]').text_content()
    print(dy1)
    page.locator('input[name="uname"]').fill('17518836160')
    page.locator('input[id="password"]').fill('123456Aa')
    time.sleep(10)
    page.click('//html/body/div/form/div/div/div/div/div[1]/div[2]/div[4]/input')
    page.click('a[id="bindSub"]')

def test_jiouxian_02(page):
    test_jiouxian_01(page)
    # 输入商品名称
    page.fill('//html/body/div[4]/div/div[2]/div[1]/form/input[1]','茅台')
    # 点击搜索
    page.click('input[class="search-btn"]')
    # 点击商品
    page.locator('img[proimgid="2045540"]').click()
    page.goto('https://www.jiuxian.com/goods-2045540.html')
    # 点击加入购物车
    page.locator('a[id="addToCartForDetail"]').click()




